//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	IRulesFactory.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System.Collections.Generic;

namespace Smart.Common.Rules
{
	/// <summary>
	/// Rules factory
	/// </summary>
	public interface IRulesFactory
	{
		/// <summary>
		/// Get current service
		/// </summary>
		/// <param name="rulesServiceName">Name of rule type</param>
		/// <returns>Service</returns>
		IRulesService GetService(string rulesServiceName);

		/// <summary>
		/// Load instance
		/// </summary>
		IRulesInstance LoadInstance(string rulesServiceName, string instanceId);

		/// <summary>
		/// Check rules for instance
		/// </summary>
		/// <returns>true, if some rules' actions applied</returns>
		bool Execute(string rulesServiceName, string instanceId);

		/// <summary>
		/// Check rules for instance
		/// </summary>
		/// <returns>true, if some rules' actions applied</returns>
		bool Execute<TInstanceType>(string rulesServiceName, TInstanceType instance)
			where TInstanceType : class, IRulesInstance;

		/// <summary>
		/// Check rule's condition
		/// </summary>
		/// <returns>true, if condition is fulfilled and action applied</returns>
		bool Execute<TRuleType, TInstanceType>(string rulesServiceName, TRuleType rule, TInstanceType instance, IDictionary<string, object> variables)
			where TRuleType : class, IRule
			where TInstanceType : class, IRulesInstance;

		/// <summary>
		/// Check rule's condition
		/// </summary>
		/// <returns>true, if condition is fulfilled and action applied</returns>
		bool Execute<TInstanceType>(string rulesServiceName, object rule, TInstanceType instance, IDictionary<string, object> variables)
			where TInstanceType : class, IRulesInstance;

		/// <summary>
		/// Check rule
		/// </summary>
		/// <returns>true, if condition is fulfilled</returns>
		bool Check<TRuleCondition, TInstanceType>(string rulesServiceName, TRuleCondition ruleCondition, TInstanceType instance, IDictionary<string, object> variables)
			where TRuleCondition : class, IRuleCondition
			where TInstanceType : class, IRulesInstance;

		/// <summary>
		/// Check rule
		/// </summary>
		/// <returns>true, if condition is fulfilled</returns>
		bool Check<TInstanceType>(string rulesServiceName, object ruleCondition, TInstanceType instance, IDictionary<string, object> variables)
			where TInstanceType : class, IRulesInstance;

		/// <summary>
		/// Execute rule's action for instance
		/// </summary>
		/// <returns>true, if applied successfully</returns>
		bool Apply<TRuleAction, TInstanceType>(string rulesServiceName, TRuleAction ruleAction, TInstanceType instance, IDictionary<string, object> variables)
			where TRuleAction : class, IRuleAction
			where TInstanceType : class, IRulesInstance;

		/// <summary>
		/// Execute rule's action for instance
		/// </summary>
		/// <returns>true, if applied successfully</returns>
		bool Apply<TInstanceType>(string rulesServiceName, object ruleAction, TInstanceType instance, IDictionary<string, object> variables)
			where TInstanceType : class, IRulesInstance;

		/// <summary>
		/// Create new securable filter
		/// </summary>
		RulesFilter CreateFilter(string rulesServiceName);

		/// <summary>
		/// Load instance
		/// </summary>
		IRulesInstance LoadInstance(string rulesServiceName, RulesFilter filter);
	}
}